package com.wish.blessingroad.controller;


import com.wish.blessingroad.common.ResponseResult;
import com.wish.blessingroad.entity.Blessing;
import com.wish.blessingroad.service.IBlessingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * <p>
 * 祝福表 前端控制器
 * </p>
 *
 * @author dhc
 * @since 2019-02-18
 */
@Controller
@RequestMapping("/blessingroad/blessing")
public class BlessingController {
    private static final Logger LOG = LoggerFactory.getLogger(BlessingController.class);

    @Autowired
    private IBlessingService blessingServiceImpl;

    /**
     * 写祈福语
     */
    @RequestMapping("/saveBlessing")
    @ResponseBody
    public Object saveBlessing(@Valid Blessing blessing) {
        return new ResponseResult<>(blessingServiceImpl.saveBlessing(blessing)).success();
    }

    /**
     * 修改祈福语
     */
    @RequestMapping("/updateBlessing")
    @ResponseBody
    public Object updateBlessing(@Valid Blessing blessing) {
        return new ResponseResult<>(blessingServiceImpl.updateById(blessing)).success();
    }

    /**
     * 根据id查询
     */
    @RequestMapping("/selectById")
    @ResponseBody
    public Object selectByIdBlessing(@RequestParam final String id) {
        return new ResponseResult<>(blessingServiceImpl.getById(id)).success();
    }

    /**
     * 根据分页查询
     *
     * @return
     */
    @RequestMapping("/selectBlessing")
    @ResponseBody
    public Object selectBlessing(Blessing blessing, int pageNumber, int pageSize) {
        return new ResponseResult<>(
                blessingServiceImpl.selectPage(blessing, pageNumber, pageSize)).success();
    }

    /**
     * 充值排行榜
     */
    @RequestMapping("/rankingBlessing")
    @ResponseBody
    public Object rankingBlessing(int pageNum, int pageSize) {
        return new ResponseResult<>(
                blessingServiceImpl.rankingBlessing(pageNum, pageSize)).success();
    }

}

